package com.example.demo.javatest.thread;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by liujiahao on 2019/4/30.
 */
public class RlockTest {
    private ReentrantLock lock=new ReentrantLock();
    private Condition con=lock.newCondition();
    private int count=0;
    public  void  method(){
        try {
            lock.lock();
            count++;
            System.out.println(count);
            con.await();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }

    }

    public static void main(String[] args) {
        RlockTest r=new RlockTest();
        Runnable run=new Runnable() {
            @Override
            public void run() {
                r.method();
            }
        };
        Thread[]  threadArry=new Thread[10];
        for (int i = 0; i <10 ; i++) {
            threadArry[i]=new Thread(run);
        }
        for (int i = 0; i <10 ; i++) {
            threadArry[i].start();
        }
    }
}
